package com.boruishangge.home.fragment;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.databinding.DataBindingUtil;
import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager;

import com.boruishangge.common.uitls.UIUtils;
import com.boruishangge.home.R;
import com.boruishangge.home.adapter.ChannelPagerAdapter;
import com.boruishangge.home.adapter.HomePagerAdapter;
import com.boruishangge.home.bean.HomeTabBean;
import com.boruishangge.home.databinding.FragmentHomeViewBinding;
import com.boruishangge.home.viewhelp.HomeFragmentViewHelp;
import com.boruishangge.persagysdk.base.BaseFragment;

import java.util.ArrayList;
import java.util.List;

public class HomeFragment extends BaseFragment {
    private FragmentHomeViewBinding binding;
    private HomePagerAdapter homePagerAdapter ;
    private List<HomeTabBean> titleList=new ArrayList<>();
    private List<Fragment> mFragmentsList=new ArrayList<>();
    View rootView;

    private static  HomeFragment   sInstance;

    public  static HomeFragment  getInstance(){
        if (sInstance == null) {
            sInstance =new  HomeFragment();
        }
        return  sInstance;
    }

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        if (rootView==null){
            rootView = inflater.inflate(R.layout.fragment_home_view, container, false);
            binding = DataBindingUtil.bind(rootView);
            initView();
            initData();
            initListener();
        }
        return  rootView;
    }


    private  void  initView(){




    }

    private  void  initData(){
        homePagerAdapter=new HomePagerAdapter(getChildFragmentManager());
        titleList.addAll(HomeFragmentViewHelp.getTabData());
        HomeFragmentViewHelp.initMagicIndicator(binding.lvMagicIndicator,binding.vpContent,titleList,getActivity());
        for (HomeTabBean name:titleList){
            HomeListFragment orderListFragment=new HomeListFragment();
            Bundle bundle = new Bundle();
            bundle.putString("name", name.getName());
            orderListFragment.setArguments(bundle);
            mFragmentsList.add(orderListFragment);
        }
        homePagerAdapter.addFragment(mFragmentsList);
        binding.vpContent.setAdapter(homePagerAdapter);
    }

    private  void  initListener(){

    }
}
